/*
 * Copyright 2009 BioTeam Inc
 * 
 * Licensed under License GNU LESSER GENERAL PUBLIC LICENSE version 3.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.gnu.org/copyleft/lesser.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */


package net.bioteam.appweb.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.bioteam.appweb.model.meta.Entry;

public class Program
    extends _Program
{

	private static final long serialVersionUID = 1L;
    protected long lastmodified;
    protected boolean demoApp;
    protected Map<String, Parameter> parametersMap;
    protected String name;
    protected List<Parameter> simpleParameters = new ArrayList<Parameter>();
    protected Parameter commandParameter;
    protected boolean acd;
    protected String file;
    
    protected Map<String, Entry> metaData;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    protected void addSimpleParameter(Parameter parameter) {
        simpleParameters.add(parameter);
    }

    /**
     *
     * @return all parameters recursively that is not paragraph
     */
    public List<Parameter> getAllParameters() {
        return simpleParameters;
    }

    /**
     *
     * @return all parameters recursively that is not paragraph and issimple=true
     */
    public List<Parameter> getSimpleParameters() {
        List<Parameter> temp = new ArrayList<Parameter>();

        for (Parameter p : simpleParameters) {
            if (p.isSimple()) {
                temp.add(p);
            } else if (p.isMandatory() && (p.getVdef() == null)) {
                temp.add(p);
            }
        }

        return temp;
    }

    public Map<String, Parameter> getParametersMap() {
        return parametersMap;
    }

    public Parameter getParameter(String name) {
        return parametersMap.get(name);
    }

    public List<Parameter> getParameters()
    {
		List p=this.get_Parameters();
		List<Parameter> x=(List<Parameter>)p;
		return x;
    }
    
    public void IndexParameters() {
    	parametersMap = new HashMap<String, Parameter>();

        for (_Parameter param : get_Parameters()) {
            indexParameters(param);
        }
    }

    private void indexParameters(_Parameter parameterIn) {
    	parametersMap.put(parameterIn.getName(), (Parameter)parameterIn);

        if (parameterIn instanceof Paragraph) {
            Paragraph paragraph = (Paragraph) parameterIn;
            for (_Parameter param : paragraph.get_Parameters()) {
                indexParameters(param);
            }

        }
    }

    public long getLastmodified() {
        return lastmodified;
    }

    public void setLastmodified(long lastmodified) {
        this.lastmodified = lastmodified;
    }

    public boolean isDemoApp() {
        return demoApp;
    }

    public void setDemoApp(boolean demoApp) {
        this.demoApp = demoApp;
    }

    public Parameter getCommandParameter() {
        return commandParameter;
    }

    public void setCommandParameter(Parameter commandParameter) {
        this.commandParameter = commandParameter;
    }

	public boolean isAcd() {
		return acd;
	}

	public void setAcd(boolean acd) {
		this.acd = acd;
	}

	public String getFile() {
		return file;
	}

	public void setFile(String file) {
		this.file = file;
	}

	public Map<String, Entry> getMetaData() {
		return metaData;
	}

	public void setMetaData(Map<String, Entry> metaData) {
		this.metaData = metaData;
	}
}
